package com.sumainfor.pc.market.controller.gmio;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.market.service.gmio.FinancialForGmioProviderService;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author Eddy·Chen
 * @Email 835033913@qq.com
 * @Create 2019-04-18 14:28
 */
@RestController
@RequestMapping("/provider/key/financial")
@Log4j2
public class FinancialForGmioProviderController {

    @Autowired
    private FinancialForGmioProviderService fgps;

    /**
     * 筛选小区数据 返回小区编号
     *
     * @param params
     * @return
     */
    @PostMapping("/filterHousingData")
    public List<Map<String, Object>> filterHousingData(@RequestBody Map<String, Object> params) {
        if (!FieldCheckUtil.isMapFieldNotNull(params, "hids")) {
            log.error("参数错误");
            return null;
        }
        return fgps.filterHousingData(params);
    }

    /**
     * 根据业主编号 查询合同的信息
     *
     * @param ownerId
     * @return
     */
    @PostMapping("/selectOwnerPactInfo")
    public Map<String, Object> selectOwnerPactInfo(String ownerId) {
        if (StringUtils.isBlank(ownerId)) {
            return null;
        }
        return fgps.selectOwnerPactInfo(ownerId);
    }

    /**
     * 查询租客合同信息
     *
     * @param tenantId
     * @param hinfoId
     * @return
     */
    @PostMapping("/getTenantPactId")
    public Map<String, Object> getTenantPactId(String tenantId, String hinfoId) {
        if (StringUtils.isBlank(tenantId) || StringUtils.isBlank(hinfoId)) {
            return null;
        }
        return fgps.getTenantPactId(tenantId, hinfoId);
    }

    /**
     * 查询房源数据
     *
     * @param hInfoId
     * @return
     */
    @PostMapping("/selectHousingInfo")
    public Map<String, Object> selectHousingInfo(String hInfoId) {
        if (StringUtils.isBlank(hInfoId)) {
            return null;
        }
        return fgps.selectHousingInfo(hInfoId);
    }


    /**
     * 根据Type类型 与编号查询 数据
     *
     * @param type 1. 项目 2. 房源
     * @param id
     * @return
     */
    @PostMapping("/selectHousingForType")
    public Map<String, Object> selectHousingForType(Integer type, String id) {
        if (type == null || StringUtils.isBlank(id)) {
            return null;
        }
        return fgps.selectHousingForType(type, id);
    }


    @PostMapping("/getHousingInfoByIdsss")
    public List<Map<String,Object>> getHousingInfoByIdsss(@RequestBody Map<String,Object> params){
        return  fgps.getHousingInfoByIdsss(params);
    }



    /**
     * 筛选小区编号 根据服务中心编号集合
     *
     * @param params
     * @return
     */
    @PostMapping("/filterCenterForHousing")
    public JsonResult filterCenterForHousing(@RequestBody Map<String, Object> params) {
        List<String> hIds = (List<String>) MapUtils.getObject(params, "hIds");
        List<Integer> miIds = (List<Integer>) MapUtils.getObject(params, "miIds");
        return fgps.filterCenterForHousing(hIds, miIds);
    }
}
